//
//  LFSettingTableViewController.m
//  LoveFruit
//
//  Created by 马海江 on 16/9/25.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFSettingController.h"
#import "LFAboutUsViewController.h"

static NSString *cellid = @"cellId";

@interface LFSettingController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, copy)NSString *text;

@end

@implementation LFSettingController
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.text = @"10.3M";
    self.navigationItem.title = @"设置";
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.equalTo(self.view);
    }];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barBuutonItemWithTarget:self action:@selector(backItem) icon:@"btn_backItem" highlighticon:nil];
    
    UIButton *quickButton = [[UIButton alloc] init];
    [quickButton setTitle:@"退出当前账号" forState:UIControlStateNormal];
    [self.view addSubview:quickButton];
    quickButton.backgroundColor = [UIColor whiteColor];
    [quickButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    quickButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [quickButton addTarget:self action:@selector(quickButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [quickButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(218);
        make.height.equalTo(@44);
        make.left.right.equalTo(self.view);
    }];
}
- (void)quickButtonClick{
    NSLog(@"退出账号");
}
- (void)backItem{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
        cell.textLabel.text = @"分享给朋友";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.row == 1){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
        cell.textLabel.text = @"关于我们";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        }
        cell.textLabel.text = @"清除缓存";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        cell.detailTextLabel.text = self.text;
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
        cell.detailTextLabel.textColor = [UIColor lightGrayColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
 
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        NSLog(@"分享给朋友");
        
    }else if (indexPath.row == 1){
        NSLog(@"关于我们");
        LFAboutUsViewController *about = [LFAboutUsViewController new];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:about];
        [self.navigationController presentViewController:nav animated:YES completion:nil];
    }else{
        NSLog(@"清除缓存");
        [SVProgressHUD show];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.text = @"0M";
            [tableView reloadData];
            [SVProgressHUD dismiss];
        });
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 8;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.1;
}
@end
